import itertools


def judge(numstr):
    nums = [int(numstr[i:i + 3]) for i in range(1, 8)]
    value = [2, 3, 5, 7, 11, 13, 17]
    for i in range(len(nums)):
        if nums[i] % value[i] == 0:
            continue
        else:
            return 0
    return 1


if __name__ == '__main__':
    numstr = '0123456789'
    nums = [j for j in numstr]
    res = 0
    for j in itertools.permutations(numstr, 10):
        if judge(''.join(j)):
            res += int(''.join(j))
    print(res)